﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using KC.DataAccess.Hub;

public partial class Search : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
	protected void btnSearch_Click(object sender, EventArgs e)
	{
		string query = txtSearch.Text.ToLower().Trim();
		HubDataContext dc = new HubDataContext();
		var pages = from p in dc.Pages
					where p.isEnabled
						&& (p.Title.ToLower().Contains(query) || p.Description.ToLower().Contains(query) || p.Body.Contains(query))
					orderby p.Created descending
					select p;
		rPages.DataSource = pages;
		rPages.DataBind();
		pnlResults.Visible = true;
	}
	protected void rPages_ItemDataBound(object sender, RepeaterItemEventArgs e)
	{
		if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem)
			return;
		KC.DataAccess.Hub.Page p = (KC.DataAccess.Hub.Page)e.Item.DataItem;

		HyperLink hlPage = (HyperLink)e.Item.FindControl("hlPage");
		hlPage.Text = Server.HtmlEncode(p.Title);
		hlPage.NavigateUrl = "http://hub.kconnolly.net/page.aspx?title=" + p.FriendlyName;

		Label lblDesc = (Label)e.Item.FindControl("lblDesc");
		lblDesc.Text = p.Description;
	}
}